﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.customer.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import com.hh.bss.base.*;
import com.hh.bss.common.cache.CustomerCache;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.customer.dao.*;
import com.hh.bss.customer.entity.*;
import com.hh.bss.customer.service.*;
import com.hh.bss.customer.vo.query.*;
import com.hh.bss.util.*;




@Service
@Transactional
public class CustomerContractServiceImpl extends BaseBusinessService<CustomerContract,java.lang.Integer>  implements CustomerContractService<CustomerContract,java.lang.Integer>{

	private CustomerContractDao customerContractDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setCustomerContractDaoImpl(CustomerContractDao dao) {
		this.customerContractDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.customerContractDao;
	}
	
	@Transactional(readOnly=true)
	public Page findPage(CustomerContractQuery query) {
		return customerContractDao.findPage(query);
	}
	public void save(CustomerContract customerContract){
		customerContractDao.save(customerContract);
		//刷新缓存
		CustomerCache.refresh();
	}
	public CustomerContract getById(Integer id){
		CustomerContract customerContract = (CustomerContract)super.getById(id);
        if (customerContract.getCustId()!=null){
			
		    Object o=customerContractDao.getJdbcDao().findFirstByQuery("select b.abbr_name,a.company_id from customer a,company b where a.company_id=b.id and a.id=? ", customerContract.getCustId());
			if (o!=null) {
				customerContract.setCustName((String)((Object[])o)[0]);				
			}
			
		}
		return customerContract;
	}
	public void removeById(Integer id){
		customerContractDao.getJdbcDao().getJdbcTemplate().update("delete from customer_contract_staff where contract_id=? ", id);
		customerContractDao.flush();
		customerContractDao.getJdbcDao().getJdbcTemplate().update("delete from customer_contract_attachment where contract_id=? ", id);
		customerContractDao.flush();
		customerContractDao.getJdbcDao().getJdbcTemplate().update("delete from customer_contract_service_company where contract_id=? ", id);
		customerContractDao.flush();
		customerContractDao.deleteById(id);
		customerContractDao.flush();
		//刷新缓存
		CustomerCache.refresh();
	}
	
}
